const express = require("express");
const blogTypeService = require("../service/blogTypeService");
const blogTypeRouter = express.Router();
const formatResponse = require("../utils/responseFormat");
//添加文章分类
blogTypeRouter.post("/", async (req, res, next) => {
  const typeInfo = req.body;
  const data = await blogTypeService.addBlogType(typeInfo);
  res.send(formatResponse(0, "", data));
});

//删除文章分类
blogTypeRouter.delete("/:id", async (req, res, next) => {
  const id = req.params.id;
  const data = await blogTypeService.deleteBlogType(id);
  res.send(formatResponse(0, "", data));
});

//修改文章分类
blogTypeRouter.put("/:id", async (req, res, next) => {
  const id = req.params.id;
  const data = await blogTypeService.updateBlogType(id, req.body);
  res.send(formatResponse(0, "", data));
});

//获取一个文章分类
blogTypeRouter.get("/:id", async (req, res, next) => {
  const id = req.params.id;
  const data = await blogTypeService.oneBlogType(id);
  res.send(formatResponse(0, "", data));
});

//获取所有文章分类
blogTypeRouter.get("/", async (req, res, next) => {
  const data = await blogTypeService.getAllBlogType();

  res.send(formatResponse(0, "", data));
});

module.exports = blogTypeRouter;
